package com.himilco.ocana.workflow.core.dao;

import java.util.Date;
import java.util.Properties;

//import javax.ejb.ActivationConfigProperty;
//import javax.ejb.MessageDriven;
//import javax.jms.JMSException;
//import javax.jms.Message;
//import javax.jms.MessageListener; 
//import javax.jms.ObjectMessage;
//import javax.jms.TextMessage;
//import javax.naming.Context;
//import javax.naming.InitialContext;
//import javax.naming.NamingException;

import com.himilco.ocana.workflow.core.dao.entities.MyMessage;

/**
 * Message-Driven Bean implementation class for: QueueListnerMDB
 * 
 */
//@MessageDriven(activationConfig = { 
//		@ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"),
//		@ActivationConfigProperty(propertyName = "destination", propertyValue = "queue/MyQueue") })
public class AgentListenerServer  { //implements MessageListener

	public AgentListenerServer() {

	}
//
//	public void onMessage(Message message) {
//		System.out.println("On message invoked!!");
//		try {
//			if (message instanceof TextMessage) {
//				System.out.println("Queue: I received a TextMessage at "+ new Date());
//				TextMessage msg = (TextMessage) message;
//				System.out.println("Message is : " + msg.getText());
//			} else if (message instanceof ObjectMessage) {
//				ObjectMessage msg = (ObjectMessage) message;
//				MyMessage myMessage = (MyMessage) msg.getObject();
//				System.out.println("Message recieved is " + "id : " + myMessage.getIdMessage() + "content"+ myMessage.getContent());
//				 preparePerstisting(); 
//			} else {
//				System.out.println("Not a valid message for this Queue MDB");
//			}
//		} catch (JMSException e) {
//			e.printStackTrace();
//		}
//
//	}
//	public void preparePerstisting() {
//		TicketManagerDALRemote bean = doLookup();
//		bean.sayHello();
//		MyMessage m = new MyMessage();
//		m.setIdMessage("2");
//		m.setContent("ok");
//		bean.storeEvent(m);  
//		
//	}
//	
//	private static TicketManagerDALRemote doLookup() {
//		Context context = null;
//		TicketManagerDALRemote bean = null;
//		try {
//			context = JNDIClient.getInitialContext();
//			String lookupName = getLookupName();
//			bean = (TicketManagerDALRemote) context.lookup(lookupName);
//		} catch (NamingException e) {
//			e.printStackTrace();
//		}
//		return bean;
//	}
//
//	private static String getLookupName() { 	
//		String appName = "";
//		String moduleName = "ocana-coreExt2";
//		String distinctName = "";
//		String beanName = TicketManagerDAL.class.getSimpleName();
//		final String interfaceName = TicketManagerDALRemote.class.getName();
//		String name = "ejb:" + appName + "/" + moduleName + "/" + distinctName	+ "/" + beanName + "!" + interfaceName;
//		System.out.println(name);
//		return name;
//	}
//	
//	static class JNDIClient {
//
//		private static Context initialContext;
//
//		private static final String PKG_INTERFACES = "org.jboss.ejb.client.naming";
//
//		public static Context getInitialContext() throws NamingException {
//			if (initialContext == null) {
//				Properties properties = new Properties();
//				properties.put(Context.URL_PKG_PREFIXES, PKG_INTERFACES);
//				initialContext = new InitialContext(properties);
//			}
//			return initialContext;
//		}
//	}

}


